<template>
  <div class="article-preview">
    <div class="article-meta">
      <nuxt-link :to="{
          name: 'profile',
          params: {
            username: data.author.username
          }
        }"
                 href="profile.html">
        <img :src="data.author.image" />
      </nuxt-link>
      <div class="info">
        <nuxt-link class="author"
                   :to="{
                      name: 'profile',
                      params: {
                        username: data.author.username
                      }
                    }">{{ data.author.username }}</nuxt-link>
        <span class="date">{{ data.createdAt | dateFormat }}</span>
      </div>
      <!-- 不能给自己点赞 -->
      <button class="btn btn-outline-primary btn-sm pull-xs-right"
              v-if="!isAuthor"
              :class="{active: data.favorited}"
              :disabled="data.favoriteDisable"
              @click="favorite(data)">
        <i class="ion-heart"></i> {{ data.favoritesCount }}
      </button>
    </div>
    <nuxt-link class="preview-link"
               :to="{
                  name: 'article',
                  params: {
                    slug: data.slug
                  }
                }">
      <h1>{{ data.title }}</h1>
      <p>{{ data.description }}</p>
      <span>Read more...</span>
    </nuxt-link>
  </div>
</template>

<script>
export default {
  name: 'ArticlePreview',
  props: {
    data: {
      type: Object,
      required: true
    },
    isAuthor: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    favorite(data) {
      this.$emit('favorite', data)
    }
  }
}
</script>

<style>
</style>